/*
 *
 *    Copyright (c) 2022 Project CHIP Authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

// THIS FILE IS GENERATED BY ZAP
// This file is generated from clusters-Commands.ipp.zapt

#include <clusters/OperationalCredentials/Commands.h>

#include <app/data-model/Decode.h>
#include <app/data-model/StructDecodeIterator.h>
#include <app/data-model/WrappedStructEncoder.h>

namespace chip
{
namespace app
{
	namespace Clusters
	{
		namespace OperationalCredentials
		{
			namespace Commands
			{
				namespace AttestationRequest
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kAttestationNonce),
							       attestationNonce);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kAttestationNonce)) {
								err = DataModel::Decode(reader, attestationNonce);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace AttestationRequest.
				namespace AttestationResponse
				{

					CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
								TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kAttestationElements),
							       attestationElements);
						encoder.Encode(to_underlying(Fields::kAttestationSignature),
							       attestationSignature);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag ==
							    to_underlying(Fields::kAttestationElements)) {
								err = DataModel::Decode(reader, attestationElements);
							} else if (__context_tag ==
								   to_underlying(Fields::kAttestationSignature)) {
								err = DataModel::Decode(reader, attestationSignature);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace AttestationResponse.
				namespace CertificateChainRequest
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kCertificateType),
							       certificateType);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kCertificateType)) {
								err = DataModel::Decode(reader, certificateType);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace CertificateChainRequest.
				namespace CertificateChainResponse
				{

					CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
								TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kCertificate), certificate);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kCertificate)) {
								err = DataModel::Decode(reader, certificate);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace CertificateChainResponse.
				namespace CSRRequest
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kCSRNonce), CSRNonce);
						encoder.Encode(to_underlying(Fields::kIsForUpdateNOC), isForUpdateNOC);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kCSRNonce)) {
								err = DataModel::Decode(reader, CSRNonce);
							} else if (__context_tag ==
								   to_underlying(Fields::kIsForUpdateNOC)) {
								err = DataModel::Decode(reader, isForUpdateNOC);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace CSRRequest.
				namespace CSRResponse
				{

					CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
								TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kNOCSRElements), NOCSRElements);
						encoder.Encode(to_underlying(Fields::kAttestationSignature),
							       attestationSignature);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kNOCSRElements)) {
								err = DataModel::Decode(reader, NOCSRElements);
							} else if (__context_tag ==
								   to_underlying(Fields::kAttestationSignature)) {
								err = DataModel::Decode(reader, attestationSignature);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace CSRResponse.
				namespace AddNOC
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kNOCValue), NOCValue);
						encoder.Encode(to_underlying(Fields::kICACValue), ICACValue);
						encoder.Encode(to_underlying(Fields::kIPKValue), IPKValue);
						encoder.Encode(to_underlying(Fields::kCaseAdminSubject),
							       caseAdminSubject);
						encoder.Encode(to_underlying(Fields::kAdminVendorId), adminVendorId);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kNOCValue)) {
								err = DataModel::Decode(reader, NOCValue);
							} else if (__context_tag == to_underlying(Fields::kICACValue)) {
								err = DataModel::Decode(reader, ICACValue);
							} else if (__context_tag == to_underlying(Fields::kIPKValue)) {
								err = DataModel::Decode(reader, IPKValue);
							} else if (__context_tag ==
								   to_underlying(Fields::kCaseAdminSubject)) {
								err = DataModel::Decode(reader, caseAdminSubject);
							} else if (__context_tag ==
								   to_underlying(Fields::kAdminVendorId)) {
								err = DataModel::Decode(reader, adminVendorId);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace AddNOC.
				namespace UpdateNOC
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kNOCValue), NOCValue);
						encoder.Encode(to_underlying(Fields::kICACValue), ICACValue);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader,
									 FabricIndex aAccessingFabricIndex)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kNOCValue)) {
								err = DataModel::Decode(reader, NOCValue);
							} else if (__context_tag == to_underlying(Fields::kICACValue)) {
								err = DataModel::Decode(reader, ICACValue);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace UpdateNOC.
				namespace NOCResponse
				{

					CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
								TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kStatusCode), statusCode);
						encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex);
						encoder.Encode(to_underlying(Fields::kDebugText), debugText);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kStatusCode)) {
								err = DataModel::Decode(reader, statusCode);
							} else if (__context_tag ==
								   to_underlying(Fields::kFabricIndex)) {
								err = DataModel::Decode(reader, fabricIndex);
							} else if (__context_tag == to_underlying(Fields::kDebugText)) {
								err = DataModel::Decode(reader, debugText);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace NOCResponse.
				namespace UpdateFabricLabel
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kLabel), label);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader,
									 FabricIndex aAccessingFabricIndex)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kLabel)) {
								err = DataModel::Decode(reader, label);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace UpdateFabricLabel.
				namespace RemoveFabric
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kFabricIndex)) {
								err = DataModel::Decode(reader, fabricIndex);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace RemoveFabric.
				namespace AddTrustedRootCertificate
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kRootCACertificate),
							       rootCACertificate);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag ==
							    to_underlying(Fields::kRootCACertificate)) {
								err = DataModel::Decode(reader, rootCACertificate);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace AddTrustedRootCertificate.
				namespace SetVIDVerificationStatement
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kVendorID), vendorID);
						encoder.Encode(to_underlying(Fields::kVIDVerificationStatement),
							       VIDVerificationStatement);
						encoder.Encode(to_underlying(Fields::kVvsc), vvsc);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader,
									 FabricIndex aAccessingFabricIndex)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kVendorID)) {
								err = DataModel::Decode(reader, vendorID);
							} else if (__context_tag ==
								   to_underlying(Fields::kVIDVerificationStatement)) {
								err = DataModel::Decode(reader,
											VIDVerificationStatement);
							} else if (__context_tag == to_underlying(Fields::kVvsc)) {
								err = DataModel::Decode(reader, vvsc);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace SetVIDVerificationStatement.
				namespace SignVIDVerificationRequest
				{

					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex);
						encoder.Encode(to_underlying(Fields::kClientChallenge),
							       clientChallenge);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kFabricIndex)) {
								err = DataModel::Decode(reader, fabricIndex);
							} else if (__context_tag ==
								   to_underlying(Fields::kClientChallenge)) {
								err = DataModel::Decode(reader, clientChallenge);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace SignVIDVerificationRequest.
				namespace SignVIDVerificationResponse
				{

					CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
								TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex);
						encoder.Encode(to_underlying(Fields::kFabricBindingVersion),
							       fabricBindingVersion);
						encoder.Encode(to_underlying(Fields::kSignature), signature);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kFabricIndex)) {
								err = DataModel::Decode(reader, fabricIndex);
							} else if (__context_tag ==
								   to_underlying(Fields::kFabricBindingVersion)) {
								err = DataModel::Decode(reader, fabricBindingVersion);
							} else if (__context_tag == to_underlying(Fields::kSignature)) {
								err = DataModel::Decode(reader, signature);
							}

							ReturnErrorOnFailure(err);
						}
					}
				} // namespace SignVIDVerificationResponse.
			} // namespace Commands
		} // namespace OperationalCredentials
	} // namespace Clusters
} // namespace app
} // namespace chip
